package com.ym.controller.medical;

import com.github.pagehelper.PageInfo;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.domain.param.StandardDeptQueryParam;
import com.ym.medical.domain.param.StandardDeptUpdateParam;
import com.ym.medical.domain.vo.StandardDeptListPcVO;
import com.ym.medical.service.IStandardDeptSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 标准科室Controller
 *
 * @author wenbo
 * @date 2020-08-25
 */
@Api(tags = "medical-标准科室")
@RestController
@Validated
@RequestMapping("/medical/standardDept")
public class StandardDeptController extends BaseController {

    @Autowired
    private IStandardDeptSV standardDeptSV;


    @ApiOperation("删除标准科室")
    @Log(printQuery = false)
    @PostMapping("/delete")
    public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
        int result = standardDeptSV.deleteByIds(ids);
        return successData(result);
    }


    @ApiOperation("标准科室列表")
    @GetMapping("/getStandardDepts")
    @ResponseBody
    public APIResponse<PageInfo<StandardDeptListPcVO>> getStandardDepts(
            @ApiParam(name = "queryParam", value = "标准科室查询信息")
                    StandardDeptQueryParam queryParam) {
        PageDomain.startPage();
        List<StandardDeptListPcVO> standardDeptModelList =
                standardDeptSV.selectListPC(queryParam);
        return successPage(standardDeptModelList);
    }

    @ApiOperation("标准科室新增")
    @PostMapping("/addSdept")
    @ResponseBody
    public APIResponse addSdept(
            @ApiParam(name = "updateParam", value = "标准科室信息", required = true)
            @RequestBody StandardDeptUpdateParam updateParam) {
        Long id = standardDeptSV.addSdept(updateParam);
        if (id > 0) {
            return successMsg("新增成功");
        }
        return failMsg("新增失败");
    }

    @ApiOperation("标准科室更改")
    @PostMapping("/updateSdept")
    @ResponseBody
    public APIResponse updateSdept(
            @ApiParam(name = "updateParam", value = "标准科室信息", required = true)
            @RequestBody StandardDeptUpdateParam updateParam) throws Exception {
        int rows = standardDeptSV.updateSdept(updateParam);
        if (rows != 1) {
            return failMsg("更改失败");
        }
        return successMsg("更改成功");
    }
}
